package com.gxc.healthfood.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxc.healthfood.entity.UserBodyMetrics;
import com.gxc.healthfood.service.UserBodyMetricsService;
import com.gxc.healthfood.mapper.UserBodyMetricsMapper;
import org.springframework.stereotype.Service;

/**
* @author hasee
* @description 针对表【user_body_metrics】的数据库操作Service实现
* @createDate 2025-10-03 16:14:50
*/
@Service
public class UserBodyMetricsServiceImpl extends ServiceImpl<UserBodyMetricsMapper, UserBodyMetrics>
    implements UserBodyMetricsService{

    /**
     * 根据用户ID查询最新的身体指标信息
     * @param userId 用户ID
     * @return 最新的身体指标信息
     */
    @Override
    public UserBodyMetrics getLatestByUserId(Long userId) {
        LambdaQueryWrapper<UserBodyMetrics> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBodyMetrics::getUserId, userId)
                .orderByDesc(UserBodyMetrics::getRecordedDate)
                .last("LIMIT 1");
        return this.getOne(queryWrapper);
    }
}




